package com.mysteel.common.utils;

import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;

import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * ProjectName: mail
 * ClassName: ParameterErrorHandlerUtils
 * Description:
 * date: 2021/03/08/008 15:57
 *
 * @author xiaochao
 */
public class ParameterErrorHandlerUtil {
    public static Map<String,String> handleException(BindingResult result){
        if (result.hasErrors()){
            Map<String, String> errors = result.getFieldErrors().stream().collect(Collectors.toMap(FieldError::getField, FieldError::getDefaultMessage));
            return errors;
        }
        return new HashMap<>();
    }
}
